//
//  ViewController.m
//  t3dFramework
//
//  Created by Tekka on 12-10-22.
//  Copyright (c) 2012年 Tekka. All rights reserved.
//

#import "ViewController.h"
#import "t3d.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize imgView;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClick:(id)sender
{
    t3dLayerPerspective(self.view.layer, 500, 0, 0);
    
    static int i = 0;
    i++;
    if (i%2)
    {
        CALayer* layer = imgView.layer;
        t3dLayerStepBackward(layer, M_PI/24);
        return ;
        
        layer.transform = CATransform3DIdentity;
        [UIView animateWithDuration:0.4
                              delay:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             t3dLayerRotateAgainstBottomLine(layer, M_PI/24);
                         }
                         completion:^(BOOL finished){
                             if (finished)
                             {
                                 layer.transform = t3dMatrixRotateAgainstBottomLine(M_PI/24, layer.bounds.size.height/2);
                                 [UIView animateWithDuration:0.2
                                                       delay:0
                                                     options:UIViewAnimationOptionCurveEaseInOut
                                                  animations:^(){
                                                      layer.transform = CATransform3DMakeTranslation(0, 0,
                                                                                                     -layer.bounds.size.height*sin(M_PI/24));;
                                                  }
                                                  completion:^(BOOL finished){
                                                  }
                                  ];
                             }
                         }
         ];
    }
    else{
        CALayer* layer = imgView.layer;
        t3dLayerStepForward(layer, M_PI/24);
        return ;
    }
}

@end
